from django.db import models
from .base_model import BaseModel
from .semester import Semester
from .grade import Grade

class SchoolSchedule(BaseModel):
    """学校日程安排模型"""
    IS_CLASS_DAY_CHOICES = (
        (1, '正常上课'),
        (2, '休息日'),
        (3, '调休'),
        (4, '课后服务'),
        (5, '考试'),
    )
    
    grade = models.ForeignKey(Grade, on_delete=models.CASCADE, verbose_name='年级')
    semester = models.ForeignKey(Semester, on_delete=models.CASCADE, verbose_name='学期')
    date = models.DateField(verbose_name='日期')
    is_class_day = models.PositiveSmallIntegerField(
        choices=IS_CLASS_DAY_CHOICES, 
        default=1, 
        verbose_name='上课状态'
    )
    remark = models.CharField(max_length=200, blank=True, verbose_name='备注')
    
    class Meta:
        verbose_name = '学校日程安排'
        verbose_name_plural = '学校日程安排'
        unique_together = ('grade', 'semester', 'date')
    
    def __str__(self):
        return f'{self.grade.name} {self.date} {self.get_is_class_day_display()}'
    
    @classmethod
    def check_class_day(cls, date):
        """检查指定日期是否为上课日"""
        return cls.objects.filter(date=date, is_class_day=1).exists()